﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;

namespace WilsonWebsite.UC
{
    public partial class Head : System.Web.UI.UserControl
    {
        string strCon = ConfigurationManager.AppSettings["Connection"];
        int catNum = Convert.ToInt32(ConfigurationManager.AppSettings["CatNum"]);

        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                BindCat(strCon);       
            }   
        }

        protected void BindCat(string strCon) 
        {
            using (DataTable dtc = Bll.Category.MULTIPLE(strCon)) 
            {
                if (dtc != null && dtc.Rows.Count > 0) 
                {
                    dtc.Columns.Add("RowId", typeof(Int32)).SetOrdinal(1);
                    for (int i = 0; i < dtc.Rows.Count; i++)
                    {
                        dtc.Rows[i]["RowId"] = i + 1;
                    }
                    var query = from q in dtc.AsEnumerable()
                                where Convert.ToInt32(q["RowId"]) <= catNum
                                select q;
                    this.repCat.DataSource = query.CopyToDataTable<DataRow>().DefaultView;
                    this.repCat.DataBind();
                }
            }
        }
    }
}